/*
 * Sw_Timers.h
 *
 *  Created on: 29/10/2012
 *      Author: uidv1378
 */

#ifndef SW_TIMERS_H_  
#define SW_TIMERS_H_

#include "derivative.h"
#include "Common.h"
#include "TPM_interface.h"
#include "evhdl_iterface.h"

#define CONFIG_NUMBER_TIMERS     ((uint8)4u)
 
#define MAX_TIMER_OBJECTS		   CONFIG_NUMBER_TIMERS			/**< This is the max number of timers that the application will have */
#define MAX_COUNTER_OBJECTS		CONFIG_NUMBER_TIMERS

#define INVALID_TIMER_ID		   0xFF		/**< This Id is returned when the timer was not created */
#define INACTIVE_TIMER           0xFFFF		/**< This number is used to tell that the timer is inactive */
#define SwTimer__nDecrementV	   ((uint8)0x01)



typedef struct
{
	//EdgarU16 timerCount;
	uint16 timerCount;
	bool bEventFlag;
	pFunc_t timerEvent;
} SwTimerObj_t;

typedef struct
{
	uint16 timerCount;
} SwCounter_t;


/** Initializes SwTimer module. Disables all timers. */
void SwTimer_Init(void);

/** This function must be called in interrupt context */
void SwTimer_ISR(void);

/** This function is for the event handler */
void SwTimer_EventHandler(void);

/** This function must be called periodically in the main loop */
void SwTimer_PeriodicTask(void);

/** Starts a timer with a given period 
	\param timerId Number of the timer to start
	\param tickPeriod_ms Timer period in ms
*/
void SwTimer_StartTimer(uint8 timerId, uint16 tickPeriod_ms);

/** Stops a timer 
	\param timerId Number of the timer to stop
*/
void SwTimer_StopTimer(uint8 timerId);

/**
	Creates a timer and assigns it call-back function.
	\param callBackFunc Function to be executed when timer has elapsed
	\return timerId The ID of the timer that was created. It returns INVALID_TIMER_ID (0xFF)
	if the timer was not created (because MAX_TIMER_OBJECTS was reached)
*/
uint8 SwTimer_CreateTimer(pFunc_t callBackFunc);

/**
	Tells if the timer has elapsed
	\param timerId Id of the timer to check
	\return TRUE if timer has elasped, FALSE if not
	*/
uint8 SwTimer_HasElapsed(uint8 timerId);



#endif /* SW_TIMERS_H_ */
